package com.ericom.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

@Entity
public class Vote extends BaseObject {

	@Override
	public String toString() {
		return new ToStringBuilder(this).append("id", id)
				.append("title", title).append("valideFrom", valideFrom)
				.append("valideTo", valideTo).toString();
	}

	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof Vote))
			return false;
		Vote castOther = (Vote) other;
		return new EqualsBuilder().append(id, castOther.id)
				.append(title, castOther.title).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(id).append(title).toHashCode();
	}

	private Long id;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name = "valide_from")
	public String getValideFrom() {
		return valideFrom;
	}

	public void setValideFrom(String valideFrom) {
		this.valideFrom = valideFrom;
	}

	@Column(name = "valide_to")
	public String getValideTo() {
		return valideTo;
	}

	public void setValideTo(String valideTo) {
		this.valideTo = valideTo;
	}

	private String title;
	private String valideFrom;
	private String valideTo;
	private Set<VoteItem> itmes = new HashSet<VoteItem>();
	private Set<Poll> polls = new HashSet<Poll>();
	@OneToMany(mappedBy = "vote", cascade = CascadeType.ALL, fetch = FetchType.LAZY, targetEntity = Poll.class)
	public Set<Poll> getPolls() {
		return polls;
	}

	public void setPolls(Set<Poll> polls) {
		this.polls = polls;
	}

	@OneToMany(mappedBy = "vote", cascade = CascadeType.ALL, fetch = FetchType.LAZY, targetEntity = VoteItem.class)
	public Set<VoteItem> getItmes() {
		return itmes;
	}

	public void setItmes(Set<VoteItem> itmes) {
		this.itmes = itmes;
	}
	

}
